package com.mingweicai.intergration.thread.pc;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class Car {

  // 是否涂蜡
  private boolean wax = false;

  // 涂蜡
  public synchronized void waxed(){
    System.out.println("涂蜡");
    wax = true;
    // 通知所有等待线程涂蜡完成
    notifyAll();
  }

  // 抛光
  public synchronized void buffed(){
    System.out.println("抛光");
    wax = false;
    // 通知所有线程抛光完成
    notifyAll();
  }

  // 等待抛光
  public synchronized void waitForWax() throws InterruptedException {
    while(!wax){
      wait();
    }
  }

  // 等待涂蜡
  public synchronized void waitForBuff() throws InterruptedException {
    // 已经涂蜡了，
    while(wax){
      wait();
    }
  }


  public static void main(String args[]){

    Car car = new Car();
    WaxOn waxOn = new WaxOn(car);
    BuffOn buffOn = new BuffOn(car);

    Executor executor = Executors.newScheduledThreadPool(10);
    executor.execute(waxOn);
    executor.execute(buffOn);

  }
}
